<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  mounted() {
    this.resizeHtml()
    if (process.env.NODE_ENV === 'development') return
    this.$nextTick(() => {
      window.addEventListener('beforeunload', this.beforeUnload)
    })
  },
  beforeDestroy() {
    if (process.env.NODE_ENV === 'development') return
    window.removeEventListener('beforeunload', this.beforeUnload)
  },
  methods: {
    resizeHtml() {
      // 计算屏幕比列调整大小
      var whdef = 16 / 1920 // 表示1920的设计图,使用100PX的默认值
      var wW = window.innerWidth // 当前窗口的宽度
      var rem = wW * whdef
      var html = document.documentElement
      html.style.fontSize = rem + 'px'
      window.onresize = () => {
        var whdef = 16 / 1920
        var wW = window.innerWidth
        var rem = wW * whdef
        var html = document.documentElement
        html.style.fontSize = rem + 'px'
      }
    },
    beforeUnload(e) {
      if (!this.$store.state.user.isLeaveToast) {
        this.$store.commit('user/SET_TOAST', true)
        return false
      }
      e = e || window.event
      if (e || window.event) e.returnValue = 1;
      return 1;
    }
  }
}
</script>
